import 'dart:convert';
import 'package:crm/http/base_result.dart';
import 'package:crm/http/http_utils.dart';
import 'package:crm/model/login.dart';
import 'package:crm/service/api_url.dart';
import 'package:dio/dio.dart';

class ApiService {
  /// 登录
  ///
  /// [email] 邮箱
  /// [password] 密码
  ///
  ///
  ///
  static Future<LoginModel> login(String lusercode, String lpassword) async {
    Response response = await HttpUtils(
      baseUrl: ApiUrl.HJ_BASE_URL,
      headers: {"Content-Type": "application/x-www-form-urlencoded"},
    ).request(ApiUrl.LOGIN,
        data: {'lusercode': lusercode, 'lpassword': lpassword}, method: 'POST');
    if (response != null &&
        response.statusCode >= 200 &&
        response.statusCode < 300) {
      BaseResult result = BaseResult.fromMap(
        json.decode(response.data),
      );
      if (result.code == '1') {
        return LoginModel.fromJson(json.decode(response.data));
      } else {
        return null;
      }
    } else {
      return null;
    }
  }
}
